//
//  WebViewController.m
//  11.17
//
//  Created by M on 16/11/22.
//  Copyright © 2016年 apple1512. All rights reserved.
//

#import "WebViewController.h"

@interface WebViewController ()<UIWebViewDelegate,UITextFieldDelegate,UISearchBarDelegate>
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *av;
@property (weak, nonatomic) IBOutlet UIWebView *web;

@end

@implementation WebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"百度";
    UISearchBar *search = [UISearchBar new];
    self.navigationItem.titleView = search;
    NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    self.web.delegate = self;
    [self.web loadRequest:req];
    [self.av startAnimating];
}


- (void)webViewDidStartLoad:(UIWebView *)webView{

}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [self.av stopAnimating];

}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
    [self.av stopAnimating];
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@",textField.text]]];
    [self.web loadRequest:request];
    
    return YES;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
